package org.rafal.springframework.domain;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Version;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;

@Entity
@NamedQueries({
		@NamedQuery(name = "App_User.findAll", query = "from App_User"),
		@NamedQuery(name = "App_User.findById", query = "select distinct a from App_User a where a.id = :id") })
public class App_User implements Serializable {

	private static final long serialVersionUID = -8451981372156119590L;

	private Long id;
	private int version;
	private String name;
	private String surname;
	private Date joinDate;
	private String idGrupy;

	public App_User() {
	}

	public App_User(String name, String surname, String idGrupy) {
		this.name = name;
		this.surname = surname;
		joinDate = new Date();
		this.idGrupy = idGrupy;
	}

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "USER_ID")
	public Long getId() {
		return id;
	}

	@Version
	@Column(name = "VERSION")
	public int getVersion() {
		return version;
	}

	@Size(min = 3, max = 20, message = "{validation.app_user.name.size}")
	@Pattern(regexp = "^[a-zA-Z0-9]+$", message = "{validation.app_user.name.pattern}")
	@Column(name = "NAME")
	public String getName() {
		return name;
	}

	@Size(min = 3, max = 20, message = "{validation.app_user.name.size}")
	@Pattern(regexp = "^[a-zA-Z0-9]+$", message = "{validation.app_user.name.pattern}")
	@Column(name = "SURNAME")
	public String getSurname() {
		return surname;
	}

	public String getIdGrupy() {
		return idGrupy;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "JOIN_DATE")
	public Date getJoinDate() {
		return joinDate;
	}

	public void setIdGrupy(String idGrupy) {
		this.idGrupy = idGrupy;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setSurname(String surname) {
		this.surname = surname;
	}

	public void setJoinDate(Date joinDate) {
		this.joinDate = joinDate;
	}

	public void setVersion(int version) {
		this.version = version;
	}

}
